package com.iuie.ns.datum.controller;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iuie.ns.datum.service.IMsgService;
import com.iuie.ns.datum.vo.PlatformMsgVO;
import com.iuie.ns.frame.web.dataset.vo.Page;
import com.iuie.ns.frame.web.response.vo.ResponseInfo;

@RequestMapping("datum/platform")
@Controller("datumPlatformController")
public class PlatformController {

	
	@Resource
	private IMsgService msgService;
	
	/**
	 * 平台首页
	 * @param request
	 * @return
	 */
	@RequestMapping
	public String index(HttpServletRequest request){
		return "view-datum/platform/platform";
	}
	
	/**
	 * 资源01页面
	 * @return
	 */
	@RequestMapping("res")
	public String resIndex() {
		return "view-datum/res";
	}
	
	/**
	 * 资源02页面
	 * @return
	 */
	@RequestMapping("res02")
	public String res02Index() {
		return "view-datum/res02";
	}
	
	/**
	 * 资源02页面-回显富文本
	 * @return
	 */
	@RequestMapping("res02/txtcontent")
	@ResponseBody
	public ResponseInfo textareaContent() {
		Map<String, String> map = new HashMap<>();
		map.put("content", "<p>\n\t<span style=\"background-color:#006600;\">safsdd</span>\n</p>\n<p>\n\t<span style=\"background-color:#006600;\"><br />\n</span>\n</p>\n<p>\n\t<span style=\"background-color:#006600;\">skdfjias</span>\n</p>\n<p>\n\t<br />\n</p>\n<p>\n\t<strong>sdafkji</strong>\n</p>");
		return ResponseInfo.successInfoByObject(map);
	}
	
	@RequestMapping("res02/selectedData")
	@ResponseBody
	public ResponseInfo findAvailableData() {
		List<PlatformMsgVO> list = new ArrayList<>();
		PlatformMsgVO p1 = new PlatformMsgVO();
		p1.setMsgId("B2647E8EF55948B6A3F0A89CAA628FB8");
		p1.setMsgTitle("标题1");
		PlatformMsgVO p2 = new PlatformMsgVO();
		p2.setMsgId("0C6FE6CC654845D09CF1C356B0BE6691");
		p2.setMsgTitle("标题2");
		list.add(p1);
		list.add(p2);
		return ResponseInfo.successInfoByObject(list);
	}
	
	@RequestMapping("res02/allData")
	@ResponseBody
	public ResponseInfo findAll() {
		List<PlatformMsgVO> list = new ArrayList<>();
		PlatformMsgVO p1 = new PlatformMsgVO();
		p1.setMsgId("B2647E8EF55948B6A3F0A89CAA628FB8");
		p1.setMsgTitle("标题1");
		PlatformMsgVO p2 = new PlatformMsgVO();
		p2.setMsgId("0C6FE6CC654845D09CF1C356B0BE6691");
		p2.setMsgTitle("标题2");
		PlatformMsgVO p3 = new PlatformMsgVO();
		p3.setMsgId("8EBD29803D644043B04E7DF8E38BAF2B");
		p3.setMsgTitle("标题3");
		PlatformMsgVO p4 = new PlatformMsgVO();
		p4.setMsgId("F866EA5F69FB4271B298E3FCF0A41EE5");
		p4.setMsgTitle("标题4");
		list.add(p1);
		list.add(p2);
		list.add(p3);
		list.add(p4);
		return ResponseInfo.successInfoByObject(list);
	}
	
	/**
	 * 查询最近的博客
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping("find/latestMsg")
	@ResponseBody
	public ResponseInfo findLatestMsg(PlatformMsgVO platformMsg, Page page) throws ParseException {
		List<PlatformMsgVO> list = msgService.findLatestMsg(platformMsg, page, null);
		return ResponseInfo.successInfo(list, page);
	}
	
}
